﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Caching;
using MyAlbum.Model;
using MyAlbum.Services;
using System.IO;

namespace PersonalAlbum
{
    public class Master
    {
        public static void AddViewData(ViewDataDictionary viewData)
        {
            PersonalAlbumModel model = new PersonalAlbumModel(
                ObjectFactory.GetInstance<IUser>(),
                ObjectFactory.GetInstance<ILanguageService>(),
               ObjectFactory.GetInstance<IConfiguration>());
            //   model.Extensions = model.Configuration.Extensions;
            viewData.Model = model;

            //for the random image box
            if (model.Configuration.ShowRandomImageBox)
            {
                viewData["RandomImage"] = new PartialRequest(new
                {
                    controller = "Entry",
                    action = "RandomImage"
                });
                if (!ConfigManager.UseCache)
                {
                    model.RandomEntries = ObjectFactory.GetInstance<IEntryService>().LoadRandomEntriesSummary(15);
                }
            }

            //Statistics box
            if (model.Configuration.ShowStatisticsBox)
            {
                viewData["StatisticsBox"] = new PartialRequest(new
                {
                    controller = "Entry",
                    action = "Statistics"
                });
                if (!ConfigManager.UseCache)
                {
                    model.Statistics = ObjectFactory.GetInstance<IStatisticsService>().Load();
                }
            }

            //latest entry box
            if (model.Configuration.ShowLatestEntryBox)
            {

                viewData["LatestEntry"] = new PartialRequest(new
           {
               controller = "Entry",
               action = "LatestEntry"
           });
                if (!ConfigManager.UseCache)
                {
                    model.LatestEntry = ObjectFactory.GetInstance<IEntryService>().GetLatestEntry();
                }
            }

            if (model.Configuration.ShowFlashTagsBox)
            {
                viewData["FlashTagCloud"] = new PartialRequest(new
                {
                    controller = "Entry",
                    action = "FlashTagCloud"
                });
                if (!ConfigManager.UseCache)
                {
                    model.TagsCloud = ObjectFactory.GetInstance<ITagEntryService>().GetTags();
                }
            }

            if (model.Configuration.ShowTagsBox)
            {
                viewData["TagsCloud"] = new PartialRequest(new
                {
                    controller = "Entry",
                    action = "TagsCloud"
                });
                if (!ConfigManager.UseCache)
                {
                    if (model.TagsCloud == null)
                    {
                        model.TagsCloud = ObjectFactory.GetInstance<ITagEntryService>().GetTags();
                    }
                }
            }

            if (model.Configuration.ShowEntriesByMonthsBox)
            {
                viewData["ByMonths"] = new PartialRequest(new
                {
                    controller = "Entry",
                    action = "ByMonths"
                });
                if (!ConfigManager.UseCache)
                {
                    model.MonthsView = ObjectFactory.GetInstance<IEntryService>().GetEntriesByMonthsSummary();
                }   
            }

            return;
            foreach (var item in model.Extensions.Where(e => e.Active))
            {
                foreach (var dataRequest in item.DataRequest)
                {
                    switch (dataRequest)
                    {
                        case DataRequest.Blogs:
                            break;
                        case DataRequest.BlogsSummary:
                            break;
                        case DataRequest.Entries:
                            break;
                        case DataRequest.Categories:
                            break;
                        case DataRequest.Albums:
                            break;
                        case DataRequest.EntriesTags:
                            if (model.TagsCloud == null)
                            {
                                model.TagsCloud = ObjectFactory.GetInstance<ITagEntryService>().GetTags();
                            }
                            break;
                        case DataRequest.CurrentPageEntries:
                            break;
                        case DataRequest.LatestEntry:
                            if (model.LatestEntry == null)
                            {
                                model.LatestEntry = ObjectFactory.GetInstance<IEntryService>().GetLatestEntry();
                            }
                            break;
                        case DataRequest.RandomEntries:
                            if (model.RandomEntries == null)
                            {
                                model.RandomEntries = ObjectFactory.GetInstance<IEntryService>().LoadRandomEntriesSummary(15);
                            }

                            break;
                        default:
                            break;
                    }
                }
            }

        }

    }
}
